﻿using System;
using System.Text;

namespace msBsc.WebUi
{
    public partial class wfShopManager : msBsc.Cls.BPDealer
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                doShowFileGrid("", "", "");
                doShowShopOrderGrid("", "", "");
            }
        }

        private void doShowFileGrid(string CurrPageNum, string strPageRowsCount, string strSort)
        {
            using (msBsc.AppLogic.DataAlc.CBizShpOrderRate oCDbAccess = new msBsc.AppLogic.DataAlc.CBizShpOrderRate())
            {
                string strSql = @"
    SELECT
    FILE_EXT
    ,FILE_COUNT=COUNT(*)
    ,FILE_SIZE=SUM(FILE_SIZE)
    FROM SYS_FILE
    WHERE
    (USER_NME='" + this.oUserInfo.Operator + @"')
    AND (FILE_EXT<>'')
    GROUP BY FILE_EXT
    "; 

                System.Data.DataSet ds = oCDbAccess.DataObj.QueryBySQL(strSql);
                string strjsontem1 = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], ""
                    , ""
                    , (CurrPageNum == string.Empty ? 1 : int.Parse(CurrPageNum))
                    , (strPageRowsCount == string.Empty ? 200 : int.Parse(strPageRowsCount))
                    , (strSort == string.Empty ? "FILE_EXT DESC" : strSort));
                this.ExecJScript(@" var data= " + strjsontem1 + @" ; 
                updatefileTableHtml( data);");
            }
        }

        private void doShowShopOrderGrid(string CurrPageNum, string strPageRowsCount, string strSort)
        {
            using (msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo oCDbAccess = new msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo())
            {
                System.Data.DataSet ds = oCDbAccess.SelectShopOrderStaticsInfo(this.oUserInfo.OperDealerId.Split(',')[0]);
                string strjsontem1 = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], ""
                    , ""
                    , (CurrPageNum == string.Empty ? 1 : int.Parse(CurrPageNum))
                    , (strPageRowsCount == string.Empty ? 200 : int.Parse(strPageRowsCount))
                    , (strSort == string.Empty ? "" : strSort));
                this.ExecJScript(@" var data= " + strjsontem1 + @" ; 
                updateOrderTableHtml( data);");
            }
        }

        public string GetCustInfo()
        {
            StringBuilder sbRet = new StringBuilder();
            string strEmail = "", strTel = "", strLastLogin = "", strShopingc = "0", strNoShopingc = "0", strScoresc = "0", strScoreNosc = "0";
            using (Epm.AppLogic.Framework.CDbAccess oCDbAccess = new Epm.AppLogic.Framework.CDbAccess())
            {
                System.Data.DataSet dst = oCDbAccess.QueryBySQL("SELECT A.LAST_LOGIN_DT,A.E_MAIL,A.TEL,B.CUST_GRADE_CID FROM SYS_USER A LEFT OUTER JOIN SHP_CUSTOMER_INFO B ON A.USER_NME = B.USER_NME WHERE A.USER_NME='" + this.oUserInfo.Operator + "'");
                if (dst.Tables[0].Rows.Count > 0)
                {
                    strEmail = dst.Tables[0].Rows[0]["E_MAIL"].ToString();
                    strTel = dst.Tables[0].Rows[0]["TEL"].ToString();
                    strLastLogin = dst.Tables[0].Rows[0]["LAST_LOGIN_DT"].ToString(); 
                }

                System.Data.DataSet dstm = oCDbAccess.QueryBySQL(@"
    SELECT 
    SHOPING_COUNT=SUM(CASE WHEN A.MALL_NO<>'1' AND A.GOODS_STATUS_SID='1' THEN 1 ELSE 0 END)
    ,NO_SHOPING_COUNT=SUM(CASE WHEN A.MALL_NO<>'1' AND A.GOODS_STATUS_SID='0' THEN 1 ELSE 0 END)
    ,SCORE_SHOPING_COUNT=SUM(CASE WHEN A.MALL_NO='1' AND A.GOODS_STATUS_SID='1' THEN 1 ELSE 0 END)
    ,SCORE_NO_SHOPING_COUNT=SUM(CASE WHEN A.MALL_NO='1' AND A.GOODS_STATUS_SID='0' THEN 1 ELSE 0 END)
    FROM SHP_GOODS_INFO A
    WHERE
    A.COMM_TENANT_ID='" + this.oUserInfo.OperDealerId.Split(',')[0] + @"'
");
                if (dstm.Tables[0].Rows.Count > 0)
                {
                    strShopingc = dstm.Tables[0].Rows[0]["SHOPING_COUNT"].ToString();
                    strNoShopingc = dstm.Tables[0].Rows[0]["NO_SHOPING_COUNT"].ToString();
                    strScoresc = dstm.Tables[0].Rows[0]["SCORE_SHOPING_COUNT"].ToString();
                    strScoreNosc = dstm.Tables[0].Rows[0]["SCORE_NO_SHOPING_COUNT"].ToString();
                }
            }
            string strPayc = "0", strReturnc = "0", strShipingc = "0", strReceiptc = "0", strReiew = "0";
            using (msBsc.AppLogic.DataAlc.CBizShpCommercialTenantInfo odataobj = new AppLogic.DataAlc.CBizShpCommercialTenantInfo())
            {
                System.Data.DataSet ds = odataobj.SelectSolpStatistic(this.oUserInfo.OperDealerId.Split(',')[0]);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    strPayc = ds.Tables[0].Rows[0]["WAIT_PAY_COUNT"].ToString();
                    strReceiptc = ds.Tables[0].Rows[0]["WAIT_RECEIPT_COUNT"].ToString();
                    strShipingc = ds.Tables[0].Rows[0]["WAIT_SHIPPING_COUNT"].ToString();
                    strReturnc = ds.Tables[0].Rows[0]["WAIT_RETURN_COUNT"].ToString();
                    strReiew = ds.Tables[0].Rows[0]["WAIT_REVIEW_COUNT"].ToString();
                }
                sbRet.Append(@"
        <div style=""height: 30px; line-height: 30px; padding-top: 5px;"">
            <font style=""font-size: 22px; font-weight: bold;color:#c40000"">" + this.oUserInfo.OperDealerId.Split(',')[1] + @"</font> <font style=""font-size: 14px;
                color: #999; font-weight: bold;"">&nbsp; &nbsp;" + "上次登录：" + strLastLogin + @"</font>
            <font style=""color: #777;""></font>
        </div>
        <div style=""height: 28px;font-size: 14px;margin-top:10px; line-height: 28px; color: #777;"">
            <span>商户编号：</span> <span>" + this.oUserInfo.OperDealerId.Split(',')[0] + @"</span>
    <a href=""/c_ShopView.htm?ID=" + this.oUserInfo.OperDealerId.Split(',')[0] + @""" target=""_blank""><span   style="""">查看店铺首页</span></a> 
        </div>
        <div style=""height: 28px;font-size: 14px; line-height: 28px; color: #777;"">
            <span>掌柜帐号：</span> <span>" + this.oUserInfo.Operator + @"</span>
        </div>
        <div style=""height: 28px;font-size: 14px; line-height: 28px; color: #777;"">
            <span>绑定邮箱：</span> <span style="""">" + strEmail + @"</span>
        </div>
        <div style=""height: 38px;font-size: 14px; line-height: 28px; color: #777; border-bottom: 1px dashed #ccc;"">
            <span>绑定手机：</span> <span style="""">" + strTel + @"</span>
        </div>
        <div id=""uOrderCount"" style="" margin-left:-100px;"">
    <a href=""/d_SoldOrderList.htm"">等待支付(<span   style=""color:#f40;"">" + strPayc + @"</span>)</a> 
    <a href=""/d_SoldOrderList.htm"">待发货(<span   style=""color:#f40;"">" + strShipingc + @"</span>)</a> 
    <a href=""/d_SoldOrderList.htm"">等待确认收货(<span   style=""color:#f40;"">" + strReceiptc + @"</span>)</a> 
    <a href=""/d_SoldOrderList.htm"">退款中(<span   style=""color:#f40;"">" + strReturnc + @"</span>)</a>
    <a href=""/d_ShopRateMana.htm"">待评价(<span   style=""color:#f40;"">" + strReiew + @"</span>)</a>
        </div>");
                sbRet.Append(@"
        <div id=""uOrderCount"" style="" margin-left:-100px;"">
    <a href=""/d_CommGoodsList.htm"">出售中的商品(<span   style=""color:#f40;"">" + strShopingc + @"</span>)</a> 
    <a href=""/d_CommGoodsList.htm"">已下架的商品(<span   style=""color:#f40;"">" + strNoShopingc + @"</span>)</a> 
        </div>");

                System.Data.DataSet dsdealer = odataobj.SelectById(this.oUserInfo.OperDealerId.Split(',')[0]);
                if (dsdealer.Tables[0].Rows.Count > 0)
                {
                    if (dsdealer.Tables[0].Rows[0]["ALLOW_SORE_MALL"].ToString() == "True")
                    {
                sbRet.Append(@"
        <div id=""uOrderCount"" style=""margin-left:-100px;"">
    <a href=""/d_ScoreGoodsList.htm"">积分商城在售商品(<span   style=""color:#f40;"">" + strScoresc + @"</span>)</a> 
    <a href=""/d_ScoreGoodsList.htm"">积分商城下架商品(<span   style=""color:#f40;"">" + strScoreNosc + @"</span>)</a> 
        </div>");
                    }
                    if (dsdealer.Tables[0].Rows[0]["LOGO_IMG_URL"].ToString() == string.Empty)
                    {
                        this.ExecJScript("$('#uHeadImg').attr('src','/themes/Style1/Image/shopblank.jpg');");
                    }
                    else
                    {
                        this.ExecJScript("$('#uHeadImg').attr('src','" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(dsdealer.Tables[0].Rows[0]["LOGO_IMG_URL"].ToString()) + "');");
                    }
                    this.ExecJScript("$('#divAccountScore').html('" + dsdealer.Tables[0].Rows[0]["SCORE_QTY"].ToString() + "');");
                    this.ExecJScript("$('#divFreezeScore').html('" + odataobj.GetShopScoreFreezeQty(this.oUserInfo.OperDealerId.Split(',')[0]).ToString() + "');");

                    this.ExecJScript("$('#divAccountAmt').html('" + dsdealer.Tables[0].Rows[0]["CHARGE_AMT"].ToString() + "');");
                
                }

            }
            return sbRet.ToString();
        }

    }
}